package com.runchinaup.smartbelt.activity;

import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.runchinaup.runchilibrary.modes.adapter.ListBaseAdapter;
import com.runchinaup.smartbelt.R;

import java.util.List;

/**
 * Created by liber on 2018/1/24.
 */

public abstract class ScanAdapter<T> extends ListBaseAdapter<T, ScanAdapter.ThisTag> {


    public ScanAdapter(Context context, List<T> datas) {
        super(context, datas);
    }

    @Override
    protected void handDataAndView(ThisTag thisTag, final T t, int position) {

        setLayoutData(thisTag, t, position);

        thisTag.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onChange(t);
            }
        });
    }

    protected abstract void setLayoutData(ThisTag thisTag, T t, int position);

    protected abstract void onChange(T t);


    @Override
    protected ThisTag instanceTag(View convertView) {
        return new ThisTag(convertView);
    }

    @Override
    protected int loaditemView() {
        return R.layout.item_blue_drivce;
    }

    public static class ThisTag extends ListBaseAdapter.Tag {

        protected TextView name;
        protected TextView mac;
        protected TextView state;
        protected RelativeLayout layout;

        public ThisTag(View view) {
            super(view);
            name = $View(R.id.drivce_name);
            mac = $View(R.id.drivce_mac);
            state = $View(R.id.drivce_state);
            layout = $View(R.id.blue_list_layout);
        }
    }

}
